package com.framework.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ArchivoUtil {

//	private static Logger log = Logger.getLogger(InicioSesionAction.class);
	
	public static void guardarArchivo(String nombre, Object serializable) {
		ObjectOutputStream objectOutputStream = null;
		try {
			
			objectOutputStream = new ObjectOutputStream(new FileOutputStream(""
					+ nombre));
			objectOutputStream.writeObject(serializable);
			objectOutputStream.flush();
			objectOutputStream.close();
			//log.info("Archivo guardado");  
		} catch (FileNotFoundException e) {
//			e.printStackTrace();
		} catch (Exception e) {
//			e.printStackTrace();
		}
	}
	
	public static Object abrirArchivo(String nombre){
		ObjectInputStream objectInputStream = null;
		Object object = null;
		try {
			objectInputStream = new ObjectInputStream(new FileInputStream("" + nombre)); 
			object = objectInputStream.readObject();
			//log.info("Archivo encontrado: " +
					//object);  
			objectInputStream.close();
		} catch (Exception e) {
//			e.printStackTrace();
		}
		return object;
	}
	
	
	public static File getDir(){
		File file = new File("lock");
		if(!file.exists()){
			file.mkdir();
		}
		return file;
	}

}
